﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;

namespace JM.JCY.SharePointComponent.IncorruptArchives.JianChaGanbuPeiOuCongYeView
{
    public partial class JianChaGanbuPeiOuCongYeViewUserControl : UserControl
    {
        public int _caseId
        {
            set { ViewState["_caseId"] = value; }
            get { return (int)ViewState["_caseId"]; }
        }

        public string _isApproval
        {
            set { ViewState["_isApproval"] = value; }
            get { return (string)ViewState["_isApproval"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (IncorruptProxy proxy = new IncorruptProxy())
                {
                    if (Request.QueryString["CaseId"] != null)
                    {
                        _caseId = Int32.Parse(Request.QueryString["CaseId"].ToString());
                        _isApproval = Request.QueryString["IsApproval"].ToString();

                        var loadDT = proxy.GetJianChaGanbuPeiOuCongYe(_caseId, string.Empty);
                        LoadForView(loadDT);
                        LoadForEdit(loadDT);

                    }
                }

            }

            // switch controls
            if (this.hfIsEdit.Value != "1")
                SwitchControls(true, false);
            else
                SwitchControls(false, true);
        }

        private void LoadForEdit(IncorruptDataSet.T_JianChaGanbuPeiOuCongYeDataTable loadDT)
        {
            var loadRow = loadDT[0];

            this.txtFillerCompany.Text = loadRow.FillerCompany;
            this.txtFiller.Text = loadRow.Filler;
            this.rbGender.SelectedValue = loadRow.Gender;
            this.txtAge.Text = loadRow.Age;
            this.txtCompany.Text = loadRow.Company_Dept;
            this.txtPosition.Text = loadRow.Position;
            this.txtRank.Text = loadRow.Rank;

            // relation1
            this.txtRelatedName1.Text = loadRow.RelatedName1;
            this.txtRelationship1.Text = loadRow.Relationship1;
            this.rbRelatedGender1.SelectedValue = loadRow.RelatedGender1;
            this.txtRelatedAge1.Text = loadRow.RelatedAge1;
            this.txtRelatedCompany1.Text = loadRow.RelatedCompany1;
            this.txtRelatedPosition1.Text = loadRow.RelatedPosition1;
            //relation2
            this.txtRelatedName2.Text = loadRow.RelatedName2;
            this.txtRelationship2.Text = loadRow.Relationship2;
            this.rbRelatedGender2.SelectedValue = loadRow.RelatedGender2;
            this.txtRelatedAge2.Text = loadRow.RelatedAge2;
            this.txtRelatedCompany2.Text = loadRow.RelatedCompany2;
            this.txtRelatedPosition2.Text = loadRow.RelatedPosition2;
            //relation3
            this.txtRelatedName3.Text = loadRow.RelatedName3;
            this.txtRelationship3.Text = loadRow.Relationship3;
            this.rbRelatedGender3.SelectedValue = loadRow.RelatedGender3;
            this.txtRelatedAge3.Text = loadRow.RelatedAge3;
            this.txtRelatedCompany3.Text = loadRow.RelatedCompany3;
            this.txtRelatedPosition3.Text = loadRow.RelatedPosition3;

            this.txtApprovalComments.Text = loadRow.ApprovalComments;
            this.hfFillDate.Value = loadRow.FillDate.ToString();
        }

        private void LoadForView(IncorruptDataSet.T_JianChaGanbuPeiOuCongYeDataTable loadDT)
        {
            var loadRow = loadDT[0];

            this.lblFillerCompany.Text = loadRow.FillerCompany;
            this.lblFillDate.Text = loadRow.FillDate.ToString(JCYConstant.Date_Format_CN);
            this.lblFiller.Text = loadRow.Filler;
            this.lblGender.Text = loadRow.Gender;
            this.lblAge.Text = loadRow.Age;
            this.lblCompany.Text = loadRow.Company_Dept;
            this.lblPosition.Text = loadRow.Position;
            this.lblRank.Text = loadRow.Rank;

            // relation1
            this.lblRelatedName1.Text = loadRow.RelatedName1;
            this.lblRelationship1.Text = loadRow.Relationship1;
            this.lblRelatedGender1.Text = loadRow.RelatedGender1;
            this.lblRelatedAge1.Text = loadRow.RelatedAge1;
            this.lblRelatedCompany1.Text = loadRow.RelatedCompany1;
            this.lblRelatedPosition1.Text = loadRow.RelatedPosition1;
            //relation2
            this.lblRelatedName2.Text = loadRow.RelatedName2;
            this.lblRelationship2.Text = loadRow.Relationship2;
            this.lblRelatedGender2.Text = loadRow.RelatedGender2;
            this.lblRelatedAge2.Text = loadRow.RelatedAge2;
            this.lblRelatedCompany2.Text = loadRow.RelatedCompany2;
            this.lblRelatedPosition2.Text = loadRow.RelatedPosition2;
            //relation3
            this.lblRelatedName3.Text = loadRow.RelatedName3;
            this.lblRelationship3.Text = loadRow.Relationship3;
            this.lblRelatedGender3.Text = loadRow.RelatedGender3;
            this.lblRelatedAge3.Text = loadRow.RelatedAge3;
            this.lblRelatedCompany3.Text = loadRow.RelatedCompany3;
            this.lblRelatedPosition3.Text = loadRow.RelatedPosition3;

            this.lblApprovalComments.Text = loadRow.ApprovalComments;
        }

        private void SwitchControls(bool isLabelsShow, bool isControlsShow)
        {
            //labels
            this.lblFillerCompany.Visible = isLabelsShow;
            this.lblFillDate.Visible = isLabelsShow;
            this.lblFiller.Visible = isLabelsShow;
            this.lblGender.Visible = isLabelsShow;
            this.lblAge.Visible = isLabelsShow;
            this.lblCompany.Visible = isLabelsShow;
            this.lblPosition.Visible = isLabelsShow;
            this.lblRank.Visible = isLabelsShow;

            // relation1
            this.lblRelatedName1.Visible = isLabelsShow;
            this.lblRelationship1.Visible = isLabelsShow;
            this.lblRelatedGender1.Visible = isLabelsShow;
            this.lblRelatedAge1.Visible = isLabelsShow;
            this.lblRelatedCompany1.Visible = isLabelsShow;
            this.lblRelatedPosition1.Visible = isLabelsShow;
            //relation2
            this.lblRelatedName2.Visible = isLabelsShow;
            this.lblRelationship2.Visible = isLabelsShow;
            this.lblRelatedGender2.Visible = isLabelsShow;
            this.lblRelatedAge2.Visible = isLabelsShow;
            this.lblRelatedCompany2.Visible = isLabelsShow;
            this.lblRelatedPosition2.Visible = isLabelsShow;
            //relation3
            this.lblRelatedName3.Visible = isLabelsShow;
            this.lblRelationship3.Visible = isLabelsShow;
            this.lblRelatedGender3.Visible = isLabelsShow;
            this.lblRelatedAge3.Visible = isLabelsShow;
            this.lblRelatedCompany3.Visible = isLabelsShow;
            this.lblRelatedPosition3.Visible = isLabelsShow;

            this.lblApprovalComments.Visible = isLabelsShow;

            //controls
            this.txtFillerCompany.Visible = isControlsShow;
            this.dtFillDate.Visible = isControlsShow;
            this.txtFiller.Visible = isControlsShow;
            this.rbGender.Visible = isControlsShow;
            this.txtAge.Visible = isControlsShow;
            this.txtCompany.Visible = isControlsShow;
            this.txtPosition.Visible = isControlsShow;
            this.txtRank.Visible = isControlsShow;

            // relation1
            this.txtRelatedName1.Visible = isControlsShow;
            this.txtRelationship1.Visible = isControlsShow;
            this.rbRelatedGender1.Visible = isControlsShow;
            this.txtRelatedAge1.Visible = isControlsShow;
            this.txtRelatedCompany1.Visible = isControlsShow;
            this.txtRelatedPosition1.Visible = isControlsShow;
            //relation2
            this.txtRelatedName2.Visible = isControlsShow;
            this.txtRelationship2.Visible = isControlsShow;
            this.rbRelatedGender2.Visible = isControlsShow;
            this.txtRelatedAge2.Visible = isControlsShow;
            this.txtRelatedCompany2.Visible = isControlsShow;
            this.txtRelatedPosition2.Visible = isControlsShow;
            //relation3
            this.txtRelatedName3.Visible = isControlsShow;
            this.txtRelationship3.Visible = isControlsShow;
            this.rbRelatedGender3.Visible = isControlsShow;
            this.txtRelatedAge3.Visible = isControlsShow;
            this.txtRelatedCompany3.Visible = isControlsShow;
            this.txtRelatedPosition3.Visible = isControlsShow;

            this.txtApprovalComments.Visible = isControlsShow;
            this.hr6.Visible = isControlsShow;
        }
    }
}
